{% extends "base.html" %}

{% block title %}停车场管理 - 车辆管理系统{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h2>停车场管理</h2>
    <a href="{{ url_for('admin_dashboard') }}" class="btn btn-secondary">返回控制台</a>
</div>

<!-- 添加停车场表单 -->
<div class="card mb-4">
    <div class="card-header">
        <h5 class="mb-0">添加新停车场</h5>
    </div>
    <div class="card-body">
        <form method="post" action="{{ url_for('admin_parking_lots') }}">
            <div class="row">
                <div class="col-md-3 mb-3">
                    <label for="name" class="form-label">停车场名称</label>
                    <input type="text" class="form-control" id="name" name="name" required>
                </div>
                <div class="col-md-3 mb-3">
                    <label for="address" class="form-label">地址</label>
                    <input type="text" class="form-control" id="address" name="address" required>
                </div>
                <div class="col-md-2 mb-3">
                    <label for="total_spaces" class="form-label">车位数量</label>
                    <input type="number" class="form-control" id="total_spaces" name="total_spaces" min="1" required>
                </div>
                <div class="col-md-2 mb-3">
                    <label for="hourly_rate" class="form-label">小时费率(¥)</label>
                    <input type="number" class="form-control" id="hourly_rate" name="hourly_rate" min="0" step="0.01" required>
                </div>
                <div class="col-md-2 d-flex align-items-end mb-3">
                    <button type="submit" class="btn btn-primary w-100">添加停车场</button>
                </div>
            </div>
        </form>
    </div>
</div>

<!-- 停车场列表 -->
<div class="card">
    <div class="card-header">
        <h5 class="mb-0">现有停车场</h5>
    </div>
    <div class="card-body">
        {% if parking_lots %}
            <div class="table-responsive">
                <table class="table table-striped" id="parking-lots-table">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>名称</th>
                            <th>地址</th>
                            <th>车位数量</th>
                            <th>小时费率</th>
                            <th>创建时间</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for lot in parking_lots %}
                            <tr>
                                <td>{{ lot.id }}</td>
                                <td>{{ lot.name }}</td>
                                <td>{{ lot.address }}</td>
                                <td>{{ lot.total_spaces }}</td>
                                <td>¥{{ "%.2f"|format(lot.hourly_rate) }}</td>
                                <td>{{ lot.created_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        {% else %}
            <p class="text-center text-muted">暂无停车场信息</p>
        {% endif %}
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
    // 可以添加表格排序、过滤等功能
    document.addEventListener('DOMContentLoaded', function() {
        // 初始化表格功能
    });
</script>
{% endblock %} 